const domainName = getApp().globalData.domainName
const parameter = getApp().globalData.parameter
const status_list = getApp().globalData.status_list
const status_bgColors = getApp().globalData.status_bgColors
const license_list = getApp().globalData.license_list
const uav_type_list = getApp().globalData.uav_type_list
const uav_level_list = getApp().globalData.uav_level_list
const pilot_rank_list = getApp().globalData.pilot_rank_list
const pilot_bgColors = getApp().globalData.pilot_bgColors
const user_id = wx.getStorageSync('user_id')
const right_list = ['is_admin',1,2,3,4]
// pages/students/test_stu/test_stu.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    right_list,
    status_list,
    status_bgColors,
    license_list,
    uav_type_list,  
    uav_level_list,
    pilot_rank_list,
    pilot_bgColors,
    show_description:null,
    loading:true,
  },

  view_test_detail(e){
    let point_id = e.currentTarget.id
    wx.navigateTo({
      url: '/pages/students/test_stu_detail/test_stu_detail?point_id=' + point_id + '&jg_stu_id=' + this.data.url_data.jg_stu_id,
    })
  },

  show_desc(e){
    let show_description = e.currentTarget.dataset.id
    if(this.data.show_description==show_description){
      this.setData({
        show_description:null
      })
    }else{
      this.setData({
        show_description
      })
    }
    let id = e.currentTarget.id
    wx.pageScrollTo({
      duration: 500,
      offsetTop: -82,
      selector: '#' + id,
    })
  },

  cancel_resit(e){
    let index = e.currentTarget.dataset.index
    this.setData({
      ['contents[' + index + '].resit']:'',
    })
  },

  resit(e){
    if(right_list.indexOf(this.data.right_limit)>-1){
      let index = e.currentTarget.dataset.index
      let index2 = e.currentTarget.dataset.index2
      let point = this.data.contents[index].points[index2].name
      wx.showActionSheet({
        itemList: ['重考'],
        alertText: '重考：' + point,
        success: res => {
          if(res.tapIndex==0){
            this.setData({
              ['contents[' + index + '].points[' + index2 + '].resit']:1,
            })
          }
        },
      })
    }

  },

  page_init(jg_stu_id, stage_id, user_id, jg_id){
    wx.request({
      url: domainName + 'test_stu_init',
      data: {jg_stu_id, stage_id, user_id, jg_id},...parameter,
      success: res => {
        this.setData({
          loading:false,
          stu_info:res.data.stu_info,
          contents:res.data.contents,
          right_limit:res.data.right_limit,
        })
      },
    })
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    let url_data = JSON.parse(decodeURIComponent(options.url_data))
    // console.log('url_data',url_data)
    this.setData({url_data})
    this.page_init(this.data.url_data.jg_stu_id, this.data.url_data.stage_id, user_id, this.data.url_data.jg_id)

  },

})